import request from '@/utils/request'
/**获取用户Id，如果已经登陆过则返回wechatId */
export const getUserId = (params: {code: string}) =>
  request.get<User.Info | string>('/user/getUserId', params)

/**登录注册 */
export const registerAppUser = (params: Api.LoginRequest) =>
  request.get<User.Info | string>('/user/registerAppUser', params)

/**获取验证码 */
export const registerGetCode = (params: {userPhone: string}) =>
  request.get('/user/registerGetCode', params)

//? 设备 -----------------------------------
/**用户绑定设备 */
export const uBindDev = (params: {userId: number | string; devGId: string}) =>
  request.get<null>('/user/uBindDev', params)

/**用户解绑设备 */
export const uDisBindDev = (params: {userId: number | string; devId: string}) =>
  request.get<null>('/user/uDisBindDev', params)

/**用户查询设备列表 */
export const uSelectMyDevListByUserId = (params: {userId: number | string}) =>
  request.get<SimpleDeviceData[]>('/user/uSelectMyDevListByUserId', params)

/**设备id 查询设备详细信息 小程序首页使用(单设备) */
export const uSelectDevDetailByDevId = (params: {
  devId: number | string
  userId: number | string
}) => request.get<Device.DevDetailData>('/user/uSelectDevDetailByDevId', params)

/**设备id 查询设备详细信息 小程序首页使用(多设备) */
export const uSelectMyDevParamAndStatus = (params: {userId: number | string}) =>
  request.get<Device.SimpleDevDetailData[]>(
    '/user/uSelectMyDevParamAndStatus',
    params
  )

/**设备id 查询设备详细信息 小程序首页使用(多设备) */
export const uSelectMyDevDataStatistic = (params: {userId: number | string}) =>
  request.get<Device.DevDataStatisticPack>(
    '/user/uSelectMyDevDataStatistic',
    params
  )

// /**获取单个设备的数据页面  小程序数据页面使用 */
// export const uSelectMyDevAnalyse = (params: { devId: number | string }) => request.get<{ devDataStatisticPack: Device.DevDataStatisticPack, paramList: Device.ParamData[] }>('/user/uSelectMyDevAnalyse', params)

/**获取单个设备的数据图表 异常数据占比*/
export const uSelectMyDevDataEcharts = (params: {
  devId: number | string
  startDate?: string
  endDate?: string
}) =>
  request.get<{
    exceptionRatio: number
    checkDataRatioPackList: Device.ParamDataRatio[]
  }>('/user/uSelectMyDevDataEcharts', params)

/**获取历史记录 多参 */
export const uSelectCheckHistoryData = (params: {
  devId: number | string
  startDate?: string
  endDate?: string
  page?: number
  size?: number
}) =>
  request.get<PagingResponse<Device.CheckHistoryData>>(
    '/user/uSelectCheckHistoryData',
    params
  )

/**查询报警记录 */
export const uSelectDevReportDataByQueryVo = (params: {
  userId: string
  devId: number | string
  startTime?: string
  endTime?: string
  page?: number
  size?: number
}) =>
  request.get<PagingResponse<Device.WarningLog>>(
    '/user/uSelectDevReportDataByQueryVo',
    params
  )

/**用户查询设备异常日志 支持多设备 异常日志 */
export const uSelectUserDevExceptionLog = (params: {
  userId: string
  devId?: number | string
  startDate?: string
  endDate?: string
  page?: number
  size?: number
}) =>
  request.get<PagingResponse<Device.AbnormalLog>>(
    '/user/uSelectUserDevExceptionLog',
    params
  )
